//
//  BKMain_PrivilegeCollectionCell.m
//  bestkeep
//
//  Created by utouu666 on 17/3/9.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BKMain_PrivilegeCollectionCell.h"
#import "BKMainCommon.h"
#import "BKMain_MyPrivilegeCell.h"
#import "BKIntegralViewController.h"
#import "BKPhoneCardsViewController.h"

@interface  BKMain_PrivilegeCollectionCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UILabel *bkHot;
@property (nonatomic, strong) UICollectionView *laterCollectionView;



@end

@implementation BKMain_PrivilegeCollectionCell


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

-(void)initialize{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _laterCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    _laterCollectionView.backgroundColor = [UIColor whiteColor];
    
    [_laterCollectionView registerClass:[BKMain_MyPrivilegeCell class] forCellWithReuseIdentifier:@"BKMain_MyPrivilegeCell"];
    _laterCollectionView.delegate = self;
    _laterCollectionView.dataSource = self;
    _laterCollectionView.showsHorizontalScrollIndicator = NO;
    [self addSubview:_laterCollectionView];
    [_laterCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.top.mas_equalTo(self.mas_top);
        make.bottom.mas_equalTo(self.mas_bottom);
    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 3;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    
    return  1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BKMain_MyPrivilegeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BKMain_MyPrivilegeCell" forIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:
            cell.typeName.text = @"积分签到";
            cell.typeImage.image = [UIImage imageNamed:@"BKMain_icon_jf"];
            break;
        case 1:
            cell.typeName.text = @"手机充值";
            cell.typeImage.image = [UIImage imageNamed:@"BKMain_icon_cz"];
            break;
        default:
            cell.typeName.text = @"我的VIP";
            cell.typeImage.image = [UIImage imageNamed:@"BKMain_icon_vip"];

            break;
    }
    
    
    
    return cell;
}



#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((SCREENWIDTH - 9)/3, SCREENWIDTH/375*81);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (section == 0) {
        return UIEdgeInsetsMake(0, 9, 0, 0);
    }else{
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BKMainViewController *mainPage  = (BKMainViewController *)self.nextResponder.nextResponder.nextResponder;
    BKIntegralViewController *integralVC = [[BKIntegralViewController alloc] init];
    BKPhoneCardsViewController *phoneCardsVC = [[BKPhoneCardsViewController alloc]init];
    if ([BKMainCommon islogin]) {
        
        switch (indexPath.item) {
            case 0:
                [mainPage.navigationController pushViewController:integralVC animated:YES];
                break;
            case 1:
                [mainPage.navigationController pushViewController:phoneCardsVC animated:YES];
                break;
            default:
                [[Mediator sharedInstance]goToMyVipFromOrignalVC:mainPage];
                break;
        }
    }else{
        Mediator *mediator = [Mediator sharedInstance];
        [mediator userGoToLoginFromOrignalController:mainPage finishBlock:^ {
            
        }];
    }

    
}

+(CGSize)calculateSize:(id)data{
    
    return CGSizeMake(SCREENWIDTH, 81*SCREENWIDTH/375);
}

- (void)fillData:(id)data{
    
    
    [self.laterCollectionView reloadData];
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

@end
